package com.example.program.data.local

import com.example.program.newmodel.FoodRecipe
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

class FoodRecipeConventer {
    private val gson = Gson()

    //定义方法将FoodRecipe转化为String
    fun foodRecipeToString(foodRecipe: FoodRecipe): String{
        return gson.toJson(foodRecipe)
    }

    //定义方法将String转化为FoodRecipe
    fun stringToFoodRecipe(recipe: String):FoodRecipe{
        val type = object : TypeToken<FoodRecipe>(){}.type
        return gson.fromJson<FoodRecipe>(recipe, type)
    }
}